﻿Imports DevComponents.DotNetBar

Public Class FrmCatalogoAutobuses

    Private Sub FrmCatalogoAutobuses_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            'TODO: esta línea de código carga datos en la tabla 'DataSet_Prod_Serv.Autobuses' Puede moverla o quitarla según sea necesario.
            Me.AutobusesTableAdapter.Fill_AutobusesNombre(Me.DataSet_Prod_Serv.Autobuses)

            lblNombre.ForeColor = SystemColors.MenuHighlight
            panelOpciones.BackColor = Color.Black
            slideOpciones.BackColor = Color.Black


            slideAcciones.IsOpen = False
            slideNuevo.IsOpen = False
            slideOpciones.IsOpen = False
            slideReportes.IsOpen = False

            For Each fila As DataGridViewRow In Me.dgvAutobuses.Rows
                If Me.dgvAutobuses.Rows(fila.Index).Cells(11).Value.ToString.Trim = "Alta" Then
                    Me.dgvAutobuses.Rows(fila.Index).Cells(0).Value = My.Resources.MB_0001_poi
                Else
                    Me.dgvAutobuses.Rows(fila.Index).Cells(0).Value = My.Resources.MB_0002_Visitors1
                End If
                Me.dgvAutobuses.Rows(fila.Index).Cells(1).Value = Me.DataSet_Prod_Serv.Autobuses.Item(fila.Index)(23)
            Next
        Catch ex As Exception
            ToastNotification.Show(Me, ex.Message, My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End Try
    End Sub

    Private Sub btnMostrarOpciones_Click(sender As Object, e As EventArgs) Handles btnMostrarOpciones.Click
        slideOpciones.IsOpen = True
    End Sub

    Private Sub AtrasBtn_Click(sender As Object, e As EventArgs) Handles AtrasBtn.Click
        Me.Close()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        slideOpciones.IsOpen = False
    End Sub

    Private Sub btnNuevo_Click(sender As Object, e As EventArgs) Handles btnNuevo.Click
        slideNuevo.IsOpen = True
    End Sub

    Private Sub btnCerrar_Click(sender As Object, e As EventArgs) Handles btnCerrar.Click
        slideNuevo.IsOpen = False
    End Sub

    Private Sub ButtonItem17_Click(sender As Object, e As EventArgs) Handles ButtonItem17.Click
        slideReportes.IsOpen = True
    End Sub

    Private Sub ButtonItem2_Click(sender As Object, e As EventArgs) Handles ButtonItem2.Click
        slideReportes.IsOpen = False
    End Sub

    Private Sub btnNuevoCapturaProducto_Click(sender As Object, e As EventArgs) Handles btnNuevoCapturaProducto.Click
        _Editar = False
        FrmCapturaAutobus.Show()
        Me.Close()
    End Sub

    Private Sub Ocultar_Panel() Handles Me.Click, dgvAutobuses.Click
        slideOpciones.IsOpen = False
        slideNuevo.IsOpen = False
        slideReportes.IsOpen = False
        slideAcciones.IsOpen = False
    End Sub

    Private Sub ButtonItem12_Click(sender As Object, e As EventArgs) Handles ButtonItem12.Click
        slideAcciones.IsOpen = True
    End Sub

    Private Sub ButtonItem19_Click(sender As Object, e As EventArgs) Handles ButtonItem19.Click
        slideAcciones.IsOpen = False
    End Sub

    Private Sub btnEditar_Click(sender As Object, e As EventArgs) Handles btnEditar.Click
        _Editar = True
        FrmCapturaAutobus.Show()
        Me.Close()
    End Sub

    Private Sub dgvAutobuses_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAutobuses.CellClick
        Try
            _IDAUTOBUS = Me.dgvAutobuses.Rows(Me.dgvAutobuses.CurrentRow.Index).Cells(2).Value
        Catch ex As Exception
            ToastNotification.Show(Me, ex.Message, My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End Try
    End Sub

    Private Sub dgvAutobuses_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAutobuses.CellDoubleClick
        btnEditar_Click(Nothing, Nothing)
    End Sub

    Private Sub btnBaja_Click(sender As Object, e As EventArgs) Handles btnBaja.Click
        If autobus.Update(Me.dgvAutobuses.CurrentRow.Cells(3).Value, Me.dgvAutobuses.CurrentRow.Cells(4).Value, Me.dgvAutobuses.CurrentRow.Cells(5).Value, Me.dgvAutobuses.CurrentRow.Cells(6).Value, Me.dgvAutobuses.CurrentRow.Cells(7).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(8).Value, Me.dgvAutobuses.CurrentRow.Cells(9).Value, Me.dgvAutobuses.CurrentRow.Cells(10).Value, "Baja", Me.dgvAutobuses.CurrentRow.Cells(12).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(13).Value, Me.dgvAutobuses.CurrentRow.Cells(14).Value, Me.dgvAutobuses.CurrentRow.Cells(15).Value, Me.dgvAutobuses.CurrentRow.Cells(16).Value, Me.dgvAutobuses.CurrentRow.Cells(17).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(18).Value, Me.dgvAutobuses.CurrentRow.Cells(19).Value, Me.dgvAutobuses.CurrentRow.Cells(20).Value, Me.dgvAutobuses.CurrentRow.Cells(21).Value, Me.dgvAutobuses.CurrentRow.Cells(22).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(23).Value, Me.dgvAutobuses.CurrentRow.Cells(24).Value, Me.dgvAutobuses.CurrentRow.Cells(2).Value) > 0 Then
            ToastNotification.Show(Me, "Actualizado con exito", My.Resources.add2, 3000, eToastGlowColor.Blue, eToastPosition.TopCenter)
        Else
            ToastNotification.Show(Me, "Nada fue modificado", My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End If
        Me.FrmCatalogoAutobuses_Load(Nothing, Nothing)
    End Sub

    Private Sub btnAlta_Click(sender As Object, e As EventArgs) Handles btnAlta.Click
        If autobus.Update(Me.dgvAutobuses.CurrentRow.Cells(3).Value, Me.dgvAutobuses.CurrentRow.Cells(4).Value, Me.dgvAutobuses.CurrentRow.Cells(5).Value, Me.dgvAutobuses.CurrentRow.Cells(6).Value, Me.dgvAutobuses.CurrentRow.Cells(7).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(8).Value, Me.dgvAutobuses.CurrentRow.Cells(9).Value, Me.dgvAutobuses.CurrentRow.Cells(10).Value, "Alta", Me.dgvAutobuses.CurrentRow.Cells(12).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(13).Value, Me.dgvAutobuses.CurrentRow.Cells(14).Value, Me.dgvAutobuses.CurrentRow.Cells(15).Value, Me.dgvAutobuses.CurrentRow.Cells(16).Value, Me.dgvAutobuses.CurrentRow.Cells(17).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(18).Value, Me.dgvAutobuses.CurrentRow.Cells(19).Value, Me.dgvAutobuses.CurrentRow.Cells(20).Value, Me.dgvAutobuses.CurrentRow.Cells(21).Value, Me.dgvAutobuses.CurrentRow.Cells(22).Value, _
                          Me.dgvAutobuses.CurrentRow.Cells(23).Value, Me.dgvAutobuses.CurrentRow.Cells(24).Value, Me.dgvAutobuses.CurrentRow.Cells(2).Value) > 0 Then
            ToastNotification.Show(Me, "Actualizado con exito", My.Resources.add2, 3000, eToastGlowColor.Blue, eToastPosition.TopCenter)
        Else
            ToastNotification.Show(Me, "Nada fue modificado", My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End If
        Me.FrmCatalogoAutobuses_Load(Nothing, Nothing)
    End Sub

    Private Sub dgvAutobuses_ColumnHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvAutobuses.ColumnHeaderMouseClick
        Try
            For Each fila As DataGridViewRow In Me.dgvAutobuses.Rows
                If Me.dgvAutobuses.Rows(fila.Index).Cells(11).Value.ToString.Trim = "Alta" Then
                    Me.dgvAutobuses.Rows(fila.Index).Cells(0).Value = My.Resources.MB_0001_poi
                Else
                    Me.dgvAutobuses.Rows(fila.Index).Cells(0).Value = My.Resources.MB_0002_Visitors1
                End If
                Me.dgvAutobuses.Rows(fila.Index).Cells(1).Value = Me.DataSet_Prod_Serv.Autobuses.Select("IDAUTOBUS=" & Me.dgvAutobuses.Rows(fila.Index).Cells(2).Value & "").ElementAt(0)(23)
            Next
        Catch ex As Exception
            ToastNotification.Show(Me, ex.Message, My.Resources.appbar_cone, 5000, eToastGlowColor.Red, eToastPosition.MiddleCenter)
        End Try
    End Sub

    Private Sub txtBusquedaCodigo_ButtonCustomClick(sender As Object, e As EventArgs) Handles txtBusquedaCodigo.ButtonCustomClick
        If txtBusquedaCodigo.Text.Trim <> "" Then
            Me.dgvAutobuses.DataSource = DataSet_Prod_Serv.Autobuses.Select("noeconomico like '" & txtBusquedaCodigo.Text.Trim & "%'")
            For Each fila As DataGridViewRow In Me.dgvAutobuses.Rows
                If Me.dgvAutobuses.Rows(fila.Index).Cells(11).Value.ToString.Trim = "Alta" Then
                    Me.dgvAutobuses.Rows(fila.Index).Cells(0).Value = My.Resources.MB_0001_poi
                Else
                    Me.dgvAutobuses.Rows(fila.Index).Cells(0).Value = My.Resources.MB_0002_Visitors1
                End If
                Me.dgvAutobuses.Rows(fila.Index).Cells(1).Value = Me.DataSet_Prod_Serv.Autobuses.Item(fila.Index)(23)
            Next
        Else
            Me.FrmCatalogoAutobuses_Load(Nothing, Nothing)
        End If
    End Sub

    Private Sub txtBusquedaCodigo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtBusquedaCodigo.KeyDown
        txtBusquedaCodigo_ButtonCustomClick(sender, e)
    End Sub

    Private Sub btnNuevoBD_Click(sender As Object, e As EventArgs) Handles btnNuevoBD.Click
        TaskDialog.Show("Cadena de conexion", "Conexión actual", My.Settings.ConnectionString, eTaskDialogButton.Close)

        'Todo esto es por si se requiere cambiar la conexion de la BD desde la aplicación (Debe reiniciar el programa para tomar la nueva BD)
        'Dim conf As Configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath)
        'Dim css As ConnectionStringsSection = conf.ConnectionStrings
        'css.ConnectionStrings("Productos_ERP.Properties.Settings.ConnectionString").ConnectionString = txt_conexion.Text
        'conf.Save()
    End Sub
End Class